﻿{
    var r = new RegExp("(^|(.*?\\/))(selDJXM.js)(\\?|$)"),
	s = document.getElementsByTagName('script'),
	src, m, baseurl = "";
    for (var i = 0, len = s.length; i < len; i++) {
        src = s[i].getAttribute('src');
        if (src) { var m = src.match(r); if (m) { baseurl = m[1]; break; } } 
    }
    inputCSS('sty.css');
}
function inputCSS(style) {
    var css = '<' + 'link rel="stylesheet" href="' + baseurl + style + '"><' + '/>';
    document.writeln(css);
}
function selDJXM() {
    this.tableName = "采矿申请登记";
    this.pagedata = new SmPageData("CKQDJK", "采矿申请登记");
    var _self = this;
    this.okcallback = null;
    var strhtml = '<div class="cls_container" id="id_div_seldjxm_div""><div><div id="id_div_query" class="queryform"><div style="margin-top: 20px; margin-left: 20px;">\
                <label>矿山名称：</label><input id="id_input_query_ksmc" class="text" /><label>许可证号：</label><input id="id_input_query_xkzh" class="text" />\
                <label>申请人：</label><input id="id_input_query_sqr" class="text" /><label>开采矿种：</label><input id="id_input_query_kczkz" class="text" />\
                <input type="button" class="btnnnn"/></div></div><hr style="border: 1 dashed #987cb9" width="98%" color="white" size="1" />\
                <div class="resultform" style="overflow-y:auto;height:360px;"><table id="id_table_selectdjxm" border="1px solid" ></table></div><div id="id_div_pagecontrol" class="go_mod_page">\
                <p id="id_select_djxm_pagecontrol" style="float: right; margin-right: 10px;margin-bottom:1px;" class="page_right"></p></div></div></div>';
    this.Show = function (callback) {
        this.okcallback = callback
        $("#id_div_seldjxm_div").remove();
        $("body").append(strhtml);
        $("#id_div_seldjxm_div").dialog({ title: "选择登记项目", position: "top", autoOpen: false, close: funCancel, top: 50, width: 960, buttons: { "确定": funOK, "取消": function () { $("#id_div_seldjxm_div").dialog("close"); } } });
        $("#id_div_seldjxm_div").dialog("open");
        $("#id_div_seldjxm_div").css("height", "510px");
        document.getElementById("id_div_seldjxm_div").parentNode.style["background"] = "#f8fae9";
        document.getElementById("id_div_seldjxm_div").parentNode.style["background-color"] = "#f8fae9";
        document.getElementById("id_div_seldjxm_div").parentNode.style["border"] = "2px solid rgb(166, 201, 226)";
        _self.pagedata.PageSize = 15;
        _self.pagedata.Key = "BSM";
        _self.pagedata.Filter = getFilter();
        _self.pagedata.Fields = "BSM, 许可证号,矿山名称,申请人 as 采矿权人,(CASE WHEN 坐标系统 IN (0,1) THEN \\\'北京54\\\' ELSE \\\'西安80\\\' END) AS 坐标系统,\
        (case when 项目类型=\\\'1020\\\'  then \\\'变更\\\' WHEN 项目类型=\\\'1030\\\' THEN \\\'延续\\\'  WHEN 项目类型=\\\'1010\\\' THEN \\\'新立\\\' END) as 项目类型,\
        签发时间 AS 签发日期, 有效期起, 有效期止, 矿区面积, 开采主矿种";
        _self.pagedata.InitEx();
        $("input:.btnnnn").click(function () { btnquery(); });
        if (_self.pagedata != null) {
            var str = "<tr class='head'><th class='th'>序号</th>";
            if (_self.pagedata.Data != null) {
                for (i = 0; i < _self.pagedata.Data.Captions.length; i++) {
                    if (_self.pagedata.Data.Captions[i] == "BSM") {
                        str += "<th class='th' style='display:none;'>" + _self.pagedata.Data.Captions[i] + "</th>";
                    } else {
                        str += "<th class='th'>" + _self.pagedata.Data.Captions[i] + "</th>";
                    }
                }
                str += "</tr>";
                if (_self.pagedata.Data.Rows.length > 0) {
                    for (i = 0; i < _self.pagedata.Data.Rows.length; i++) {
                        str += "<tr><th class='th2'>" + (i + 1) + "</th>";
                        for (j = 0; j < _self.pagedata.Data.Captions.length; j++) {
                            if (j == 0) {
                                str += "<td style='display:none;'>" + _self.pagedata.Data.Rows[i][j] + "</td>";
                            } else {
                                str += "<td>" + _self.pagedata.Data.Rows[i][j] + "</td>";
                            } 
                        }
                        str += "</tr>";
                    }
                }
                $("#id_table_selectdjxm").append(str);
            }
            InitPageControlEx();
        }
    }
    function funOK() {
        if ($("#id_div_seldjxm_div tr:.selected not(.head)") != null) {
            if ($("#id_div_seldjxm_div tr:.selected:not(.head)").length == 1) {
                if (_self.okcallback != null) {
                    //alertex($("#id_div_seldjxm_div tr:.selected:not(.head) td:eq(0)").text())
                    _self.okcallback($("#id_div_seldjxm_div tr:.selected:not(.head) td:eq(0)").text());
                    $("#id_div_seldjxm_div").dialog("close");
                }
            }
        }
    }
    function funCancel() {
        $("#id_div_seldjxm_div").remove();
    }
    function InitPage() {
        $("#id_div_seldjxm_div tr:not(.head)").remove();
        if (_self.pagedata != null) {
            var str = '';
            if (_self.pagedata.Data.Rows.length > 0) {
                for (i = 0; i < _self.pagedata.Data.Rows.length; i++) {
                    str += "<tr><th class='th2'>" + (i + 1) + "</th>";
                    for (j = 0; j < _self.pagedata.Data.Captions.length; j++) {
                        if (j == 0) {
                            str += "<td style='display:none;'><span>" + _self.pagedata.Data.Rows[i][j] + "</span></td>";
                        } else {
                            str += "<td><span>" + _self.pagedata.Data.Rows[i][j] + "</span></td>";
                        } 
                    }
                    str += "</tr>";
                }
            }
            $("#id_table_selectdjxm").append(str);
        }
        InitPageControlEx();
    }
    function btnquery() {
        var strfilter = getFilter();
        _self.pagedata.Filter = strfilter;
        _self.pagedata.InitEx();
        InitPage();
    }
    function page(pageindex) {
        if (pageindex != _self.pagedata.PageIndex) {
            _self.pagedata.PageIndex = pageindex;
            btnquery();
        }
    }
    function getFilter() {
        var str = '';
        var ksmc = $("#id_input_query_ksmc").val();
        var xkzh = $("#id_input_query_xkzh").val();
        var sqr = $("#id_input_query_sqr").val();
        var kczkz = $("#id_input_query_kczkz").val();
        if (ksmc != null && ksmc != '') {
            str += "矿山名称 like \\\'%" + ksmc + "%\\\' and";
        }
        if (xkzh != null && xkzh != '') {
            str += " 许可证号 like \\\'%" + xkzh + "%\\\' and";
        }
        if (sqr != null && sqr != '') {
            str += " 申请人 like \\\'%" + sqr + "%\\\' and";
        }
        if (kczkz != null && kczkz != '') {
            str += " 开采主矿种 like \\\'%" + kczkz + "%\\\' and";
        }
        str += " 项目类型>50 and";
        if (str != '') {
            str = str.substr(0, str.length - 3);
        }
        return str;
    }
    function InitPageControlEx() {
        $("#id_div_seldjxm_div tr").click(function () { $("#id_div_seldjxm_div tr.selected").removeClass("selected"); $(this).addClass("selected"); });
        $("#id_div_seldjxm_div tr").dblclick(function () { funOK(); });
        var ele = $("#id_select_djxm_pagecontrol");
        var strPre = _self.pagedata.PageIndex == 1 ? '<span class="prev" ><span></span>上一页</span>&nbsp;' : '<a  title="上一页" class="prev"><span></span>上一页</a>';
        ele.html(strPre);
        if (_self.pagedata.PageCount <= 7) {
            for (i = 1; i <= _self.pagedata.PageCount; i++) {
                ele.append('<a title="第' + i + '页">' + i + '</a>&nbsp;');
            }
        }
        else {
            if (_self.pagedata.PageIndex >= 5) {
                ele.append('<a title="第' + 1 + '页">' + 1 + '</a>&nbsp;');
                ele.append('<span class="point">...</span>');
                if (_self.pagedata.PageIndex < _self.pagedata.PageCount - 3) {
                    for (j = _self.pagedata.PageIndex - 2; j <= _self.pagedata.PageIndex + 2; j++) {
                        ele.append('<a title="第' + j + '页">' + j + '</a>&nbsp;');
                    }
                    ele.append('<span class="point">...</span>');
                    ele.append('<a title="第' + _self.pagedata.PageCount + '页">' + _self.pagedata.PageCount + '</a>&nbsp;');
                }
                else {
                    for (j = _self.pagedata.PageCount - 5; j <= _self.pagedata.PageCount; j++) {
                        ele.append('<a title="第' + j + '页">' + j + '</a>&nbsp;');
                    }
                }
            }
            else {
                for (j = 1; j <= 6; j++) {
                    ele.append('<a title="第' + j + '页">' + j + '</a>&nbsp;');
                }
                ele.append('<span class="point">...</span>');
                ele.append('<a title="第' + _self.pagedata.PageCount + '页">' + _self.pagedata.PageCount + '</a>&nbsp;');
            }
        }
        $("#id_select_djxm_pagecontrol").css("cursor", "pointer");
        var strNext = _self.pagedata.PageIndex == _self.pagedata.PageCount || _self.pagedata.PageCount == 0 ? '<span class="next" ><span></span>下一页</span>' : '<a title="下一页" class="next"><span></span>下一页</a>';
        ele.append(strNext);
        $("#id_select_djxm_pagecontrol a").click(function () { var tit = $(this).attr("title"); if (tit == "上一页") { page(_self.pagedata.PageIndex - 1); } else if (tit == "下一页") { page(_self.pagedata.PageIndex + 1); } else { page(parseInt(tit.substr(1, tit.length - 2))); } });
        $('a[title="第' + _self.pagedata.PageIndex + '页"]').addClass("current");
    }
}
